import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { User } from '@/modules/system/user/entities/user.entity';
import { BaseTimeEntity } from '@/common/entities/base-time.entity';
import { TABLE_PREFIX } from '@/config';

@Entity({ name: `${TABLE_PREFIX}sys_user_subuser` })
export class UserSubuser extends BaseTimeEntity {
    @PrimaryGeneratedColumn()
    id: number;
    
    @Column("int")
    userId: number;
    
    @Column("int")
    subuserId: number;
    
    @ManyToOne(() => User, (user) => user.id, { onDelete: "CASCADE" })
        // @JoinColumn({ name: 'userId' }) // 设置列名为'userId'，与TypeORM自动生成的列名相同
    user: User;
    
    @ManyToOne(() => User, (user) => user.id, { onDelete: "CASCADE" })
        // @JoinColumn({ name: 'userId' }) // 设置列名为'userId'，与TypeORM自动生成的列名相同
    subuser: User;
}
